home *** CD-ROM | disk | FTP | other *** search
/ Clickx 75 / Clickx 75.iso / software / expressionweb / expressionwebv3 / ExpressionWeb_en.exe / Setup / WeLocen.cab / xWeb.FPUTLSAT.dll.en / HTML / 5005 next >
Encoding:
Extensible Markup Language  |  2009-07-15  |  3.8 KB  |  133 lines

  1. <xsl:stylesheet 
  2.     version="1.0" 
  3.     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  4.     xmlns:wp="http://schemas.microsoft.com/WebPart/v2">
  5. <xsl:output 
  6.     method="xml" 
  7.     indent="no" 
  8.     omit-xml-declaration="yes" />
  9. <xsl:strip-space elements="*" />
  10.  
  11. <xsl:param name="whoHasCDATAs"></xsl:param>
  12. <xsl:param name="tabChar" select="' '"/>
  13. <xsl:param name="preindent" select="''"/>
  14.  
  15. <!-- 
  16. a very simple pretty-printer for XML; 
  17. once upon a time, the XML DOM did something 
  18. like this when the Save() method was called;
  19. the ' ' business below is a newline
  20. -->
  21.  
  22. <xsl:template match="*">
  23.     <xsl:call-template name="standard"/>
  24. </xsl:template>
  25.  
  26. <xsl:template name="standard">
  27.     <xsl:variable name="haskids" select="count(*) > 0" />
  28.     <xsl:call-template name="indent" />
  29.     <xsl:choose>
  30.         <xsl:when test="count(*|comment()|processing-instruction()|text()) > 0">
  31.             <xsl:copy>
  32.                 <xsl:copy-of select="@*" />
  33.                 <xsl:apply-templates />
  34.                 <xsl:if test="$haskids">
  35.                     <xsl:call-template name="indent" />
  36.                 </xsl:if>
  37.             </xsl:copy>
  38.         </xsl:when>
  39.         <xsl:otherwise>
  40.             <xsl:copy>
  41.                 <xsl:copy-of select="@*" />
  42.             </xsl:copy>
  43.         </xsl:otherwise>
  44.     </xsl:choose>
  45. </xsl:template>
  46.  
  47. <xsl:template match="wp:DataQuery|wp:XSL|wp:Content">
  48.                         
  49.     <xsl:choose>
  50.         <xsl:when test="contains( $whoHasCDATAs,local-name() )">
  51.             <xsl:variable name="haskids" select="count(*) > 0" />
  52.             <xsl:value-of select="' '" />
  53.             <xsl:copy>
  54.                     <xsl:copy-of select="@*" />
  55.                     <xsl:text disable-output-escaping="yes"><![CDATA[</xsl:text>
  56.                     <xsl:value-of select="." disable-output-escaping="yes"/>
  57.                     <xsl:text disable-output-escaping="yes">]]></xsl:text>
  58.             </xsl:copy>
  59.         </xsl:when>
  60.         <xsl:otherwise>
  61.             <xsl:call-template name="standard"/>
  62.         </xsl:otherwise>
  63.     </xsl:choose>
  64. </xsl:template>
  65.  
  66. <xsl:template match="a[img]">
  67.     <xsl:call-template name="indent" />
  68.     <xsl:copy>
  69.         <xsl:copy-of select="@*" />
  70.         <xsl:apply-templates mode="noindent" />
  71.     </xsl:copy>
  72. </xsl:template>
  73.  
  74. <xsl:template match="*" mode="noindent">
  75.     <xsl:copy>
  76.         <xsl:copy-of select="@*"/>
  77.         <xsl:apply-templates mode="noindent" />
  78.     </xsl:copy>
  79. </xsl:template>
  80.  
  81. <!-- 
  82.     We strip the crs off the end of the text
  83.     nodes. What happens is that the text nodes include
  84.     all the whitespace after the last printable char. Thus
  85.     each time a text node is followed by a tag (which is preceded
  86.     by a CR, then the CR becomes part of the text node on teh 
  87.     next iteration
  88. -->
  89. <xsl:template name="strip-crs">
  90.     <xsl:param name="text"/>
  91.     <xsl:variable name="sp" select="' '" />
  92.     <xsl:variable name="tab" select="' '" />
  93.     <xsl:variable name="cr" select="' '" />
  94.     <xsl:variable name="lf" select="' '" />
  95.     <xsl:choose>
  96.         <xsl:when test="
  97.                     substring($text,string-length($text)) = $cr
  98.                     or substring($text,string-length($text)) = $lf
  99.                     or substring($text,string-length($text)) = $sp
  100.                     or substring($text,string-length($text)) = $tab">
  101.             <xsl:variable name="result">
  102.                 <xsl:call-template name="strip-crs">
  103.                     <xsl:with-param name="text" select="substring($text,1,string-length($text)-1)"/>
  104.                 </xsl:call-template>
  105.             </xsl:variable>
  106.             <xsl:value-of select="$result"/><xsl:text> </xsl:text>
  107.         </xsl:when>
  108.         <xsl:otherwise>
  109.             <xsl:value-of select="$text"/>
  110.         </xsl:otherwise>
  111.     </xsl:choose>
  112. </xsl:template>
  113.  
  114. <xsl:template match="text()">
  115.     <xsl:call-template name="strip-crs">
  116.         <xsl:with-param name="text"><xsl:value-of select="."/></xsl:with-param>
  117.     </xsl:call-template>
  118. </xsl:template>
  119.  
  120. <xsl:template match="comment()|processing-instruction()">
  121.     <xsl:call-template name="indent" />
  122.     <xsl:copy/>
  123. </xsl:template>
  124.  
  125. <xsl:template name="indent">
  126.     <xsl:value-of select="' '" />
  127.     <xsl:for-each select="ancestor::*">
  128.         <xsl:value-of select="$preindent" /><xsl:value-of select="$tabChar" />
  129.     </xsl:for-each>
  130. </xsl:template>
  131.  
  132. </xsl:stylesheet>
  133.